package com.becca.cake.core.excel.excelWriter;

import java.util.List;

import com.becca.cake.util.StringUtil;

/**
 * 通用EXCEL导出数据封装类
 * @author hejinguo
 * @version $Id: ExcelInfo.java, v 0.1 2014-4-23 下午09:20:09
 */
public class ExcelInfo {
    private List<Object> datas;                   //数据(必填) 
    private String       columnHeader[];          // 列的标题名称(必填)
    private String       feilds[];                // 返回结果集的字段名称
    private String       fieldType[];             //列的类型
    private String       dataStat[];              //列数据是否需要统计
    private String       footer[][];
    private String       title;                   //头部标题 (必填)
    private int          width[];                 //列宽
    private String       fileName = "ExcelExport"; //必填
    private String       sheetName;               //必填

    public String getSheetName() {
        if (StringUtil.isEmpty(sheetName)) {
            this.setSheetName("Sheet");
        }
        return sheetName;
    }

    public void setSheetName(String sheetName) {
        this.sheetName = sheetName;
    }

    public String[] getColumnHeader() {
        return columnHeader;
    }

    public void setColumnHeader(String columnHeaders) {
        if (columnHeaders != null) {
            this.columnHeader = columnHeaders.split(",");
        } else {
            this.columnHeader = null;
        }
    }

    public String[] getFeilds() {
        return feilds;
    }

    public void setFeilds(String feilds) {
        if (feilds != null) {
            this.feilds = feilds.split(",");
        } else {
            this.feilds = null;
        }
    }

    public String[][] getFooter() {
        return footer;
    }

    public void setFooter(String[][] footer) {
        this.footer = footer;
    }

    public int[] getWidth() {
        return width;
    }

    public void setWidth(int[] width) {
        this.width = width;
    }

    public String[][] getTitle() {
        String[][] ttAry = null;
        if (StringUtil.isNotEmpty(title)) {
            ttAry = new String[1][2];
            ttAry[0][0] = title;
            ttAry[0][1] = "center";
            if (StringUtil.isEmpty(title)) {
                ttAry[0][0] = "Excel导出数据";
            }
        }
        return ttAry;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public List<Object> getDatas() {
        return datas;
    }

    public void setDatas(List<Object> datas) {
        this.datas = datas;
    }

    public String[] getFieldType() {
        return fieldType;
    }

    public void setFieldType(String fieldType) {
        if (fieldType != null) {
            this.fieldType = fieldType.split(",");
        } else {
            this.fieldType = null;
        }
    }

    public Object[][] getDataStat() {
        Object dataAry[][] = null;
        int rows = datas.size();
        int columns = feilds.length;
        if (rows == 0 || columns == 0) {
            return null;
        }
        dataAry = new Object[rows][];
        for (int i = 0; i < rows; i++) {
            Object obj = datas.get(i);
            if (obj == null) {
                continue;
            }
            dataAry[i] = new Object[columns];
            for (int j = 0; j < columns; j++) {
                dataAry[i][j] = ExcelWriteUtils.getParameter(obj, feilds[j]);
            }
        }
        return dataAry;
    }

    public void setDataStat(String dataStat) {
        if (dataStat != null) {
            this.dataStat = dataStat.split(",");
        } else {
            this.dataStat = null;
        }
    }

}
